// pages/orderGoods/orderGoods.js
Page({
  data: {
    globalData: getApp().globalData,
    navbar: [{
      title: '全部',
      header: '交易关闭',
      footer: '删除订单'
    }, {
      title: '待付款',
      header: '等待买家付款',
      footer: '去付款'
    }, {
      title: '待发货',
      header: '等待卖家发货',
      footer: '催发货'
    }, {
      title: '待收货',
      header: '卖家已发货',
      footer: '确认收货'
    }, {
      title: '待评价',
      header: '交易成功',
      footer: '删除订单'
    }],
    active: 0,
    orders: []
  },

  onLoad(options) {
    this.setData({active: parseInt(options.status)})
    this.getOrders(parseInt(options.status))
  },

  getOrders(status) {
    let that = this
    wx.request({
      url: that.data.globalData.server + '/order/query',
      method: 'GET',
      data: {
        userId: wx.getStorageSync('user').userId,
        status: status === 0 ? '' : status,
        pageNum: 1,
        pageSize: 10
      },
      success(res) {
        that.setData({
          orders: res.data.data.records
        })
      }
    })
  },
  switch(e) {
    this.setData({active: e.currentTarget.dataset.status})
    this.getOrders(e.currentTarget.dataset.status)
  },
  toOrderDetail(e) {
    wx.navigateTo({url: '/pages/orderDetail/orderDetail?id=' + e.currentTarget.dataset.id})
  }

  
})